package com.baselibrary.libs.View.defined.defined_viewpager;

import android.content.Context;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.view.View;
import com.baselibrary.libs.R;
import com.baselibrary.libs.Utils.log.LogUtils;
import com.baselibrary.libs.View.My.MyViewPger;
import com.baselibrary.libs.View.baseView.BaseView;
import com.baselibrary.libs.example.example_viewpager_fragment.view.MyViewPagerAdapter;

import java.util.ArrayList;

/**
 * Created by 35876 于萌萌
 * 创建日期: 14:32 . 2017年01月30日
 * 描述:
 * <p>
 * <p>
 * 备注:
 */

public class Defined_ViewPager extends BaseView{

    private MyViewPger mMyViewPger;

    public MyViewPagerAdapter getAdapter() {
        return mAdapter;
    }

    private MyViewPagerAdapter mAdapter;

    public Defined_ViewPager(Context context) {
        super(context);
    }

    public Defined_ViewPager(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public Defined_ViewPager(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    public int getXml() {
        return R.layout.defined_viewpager;
    }

    @Override
    public void initView(View view) {
        mMyViewPger = (MyViewPger) view.findViewById(R.id.MyViewPger);


    }

    /**
     * 设置适配器
     * @param fm
     * @param fragments
     * @return
     */
    public Defined_ViewPager setData(FragmentManager fm, ArrayList<Fragment> fragments){
        mAdapter = new MyViewPagerAdapter(fm, fragments);
        mMyViewPger.setAdapter(mAdapter);

        mMyViewPger.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
                LogUtils.i("滑动_onPageScrolled\t"+"滑动开始的时候的页\t"+position+"\tpositionOffset\t"+positionOffset+"\tpositionOffset\t"+positionOffset);

            }

            @Override
            public void onPageSelected(int position) {
                LogUtils.i("滑动_的页\t"+position);
            }

            @Override
            public void onPageScrollStateChanged(int state) {
                LogUtils.i("滑动_的状态\t"+state);
            }
        });
        return this;
    }

        public MyViewPger getMyViewPger(){
            return mMyViewPger;
        }
}
